#ifndef __types_h__
#define __types_h__

#include "system.h"
#include <math.h>

namespace core
{



/*
 * @brief: common
 */
typedef unsigned long dword;
typedef unsigned short word;
typedef unsigned int uint;



/*
 *@brief: define color
 */
struct color
{
    union
    {
        unsigned long val;
        struct rgb
        {
            byte r;
            byte g;
            byte b;
            byte a;
        }rgbVal;
    };

    color()
        : val(0)
    {
    }

    color( unsigned long value )
        : val(value)
    {
    }

    operator unsigned long()
    {
        return val;
    }
};





/*
 * @brief: rect
 */
struct size
{
    int x;
    int y;

    size()
        : x(0)
        , y(0)
    {
    }

    void set( int x, int y )
    {
        this->x = x;
        this->y = y;
    }

    void empty()
    {
        x = y = 0;
    }
};





/*
 * @brief: rect
 */
struct rect
{
    int left;
    int top;
    int right;
    int bottom;

    rect()
        : left(0)
        , top(0)
        , right(0)
        , bottom(0)
    {
    }

    int width() const
    {
        return right - left;
    }

    int height() const
    {
        return bottom - top;
    }

    void set( int l, int t, int r, int b )
    {
        left = l;
        top = t;
        right = r;
        bottom = b;
    }

    void offset( int x, int y )
    {
        left += x;
        right += x;
        top += y;
        bottom += y;
    }

    void empty()
    {
        left = top = right = bottom = 0;
    }

    bool test( int x, int y )
    {
        if( x >= left && x <= right && y <= bottom && y >= top )
        {
            return true;
        }
        return false;
    }

    rect intersect( const rect &r )
    {
        rect result;
        int ml = max( left, r.left );
        int mr = min( right, r.right );
        int mt = max( top, r.top );
        int mb = min( bottom, r.bottom );

        result.set( ml, mt, mr, mb );
        return result;
    }

    bool contains( const rect &r )
    {
        rect result = intersect( r );
        if( result.valid() )
        {
            return true;
        }

        return false;
    }

    rect unionsect( const rect &r )
    {
        rect result;
        int ml = min( left, r.left );
        int mr = max( right, r.right );
        int mt = min( top, r.top );
        int mb = max( bottom, r.bottom );

        result.set( ml, mt, mr, mb );
        return result;
    }

    void inflate( int l, int t, int r, int b )
    {
        left -= l;
        top -= t;
        right += r;
        bottom += b;
    }

    void deflate( int l, int t, int r, int b )
    {
        left += l;
        top += t;
        right -= r;
        bottom -= b;
    }

    bool valid()
    {
        return ((right >= left) && (bottom >= top));
    }
};





/*
 * @brief: unit
 */
struct unit
{
    int      use;
    bool     pixel;

    unit() 
        : use(0)
        , pixel(true)
    {
    }

    int operator()( int length ) const
    {
        if( !pixel )
        {
            return use * length / 100;
        }
        return use;
    }

    unit & operator=( int u )
    {
        use = u;
        pixel = true;
        return *this;
    }
};





/*
 * @brief: layout
 */
struct layout
{
    bool   leaf;
    dword  fit;
    rect   content;
    int    width;
    int    height;
    int    row;
    int    col;
    int    baseline;
    rect   boundary;
    uint   eparam;

    layout()
        : leaf(true)
        , fit(0)
        , width(0)
        , height(0)
        , row(0)
        , col(0)
        , baseline(0)
        , eparam(0)
    {
    }
};





/*
 * @brief: adjust
 */
struct adjust
{
    int x;
    int y;
    bool vertical;

    adjust()
        : x(0)
        , y(0)
        , vertical(false)
    {
    }
};



}

#endif